<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="../javascript/lib/jquery.js"></script>
</head>
<body>

<div id="list"></div>
<script>

    (function(){


        function getPoint() {
            var x = 1;
            var y = 10;
            return {x, y};
        }
        getPoint()// {x:1, y:10}


        //ES6 允许字面量定义对象时，用方法二（表达式）作为对象的属性名，即把表达式放在方括号内。
        let propKey = 'foo';

        let obj = {
            [propKey]: true,
            ['a' + 'bc']: 123
        };

    });

    (function(){

        //Object.is------------------------
        +0 === -0 //true
        NaN === NaN // false

        Object.is(+0, -0) // false
        Object.is(NaN, NaN) // true


        //Object.assign方法用于对象的合并
        var target = { a: 1 };

        var source1 = { b: 2 };
        var source2 = { c: 3 };

        Object.assign(target, source1, source2);
        target // {a:1, b:2, c:3}

        //Object.assign方法实行的是浅拷贝,如果源对象某个属性的值是对象，那么目标对象拷贝得到的是这个对象的引用。

        //常见用途-------------------------------
        Object.assign(SomeClass.prototype, {
            someMethod(arg1, arg2) {

            },
            anotherMethod() {

            }
        });

        // 等同于下面的写法
        SomeClass.prototype.someMethod = function (arg1, arg2) {

        };
        SomeClass.prototype.anotherMethod = function () {

        };

    });


    //对象原型Object.getPrototypeOf() Object.setPrototypeOf()
    (function(){

        let proto = {};
        let obj1 = { a: 10 };
        Object.setPrototypeOf(obj1, proto);


        proto.y = 20;
        proto.z = 40;

        obj1.x // 10
        obj1.y // 20
        obj1.z // 40

        console.log(Object.getPrototypeOf(obj1))


        //Object.entries
        let obj = { one: 1, two: 2 };
        for (let [k, v] of Object.entries(obj)) {
            console.log(
                `${JSON.stringify(k)}: ${JSON.stringify(v)}`
            );
        }
        // "one": 1
        // "two": 2


    });

    //扩展运算符****************************
    (function(){

        let [a,b,...c] = [1,2,3,4,5,6,7]

        console.log(c)


        let ab = { ...a, ...b };
        // 等同于
        let ab = Object.assign({}, a, b);

    });



    (function(){

        //Object.getOwnPropertyDescriptors方法，返回指定对象所有自身属性（非继承属性）的描述对象。
        const obj = {
            foo: 123,
            get bar() { return 'abc' }
        };

        Object.getOwnPropertyDescriptors(obj)
        // { foo:
        //    { value: 123,
        //      writable: true,
        //      enumerable: true,
        //      configurable: true },
        //   bar:
        //    { get: [Function: bar],
        //      set: undefined,
        //      enumerable: true,
        //      configurable: true }
        //    }

    });




</script>
</body>
</html>






















